//最大子数组和
//测试链接：https://leetcode.cn/problems/maximum-subarray/submissions/659286478/
public class MaxSubArray {
    public int maxSubArray(int[] nums) {
        // 1. 创建 dp 表
        // 2. 初始化
        // 3. 填表
        // 4. 返回结果
        int n = nums.length;
        int[] dp = new int[n + 1];
        int ret = Integer.MIN_VALUE;
        for (int i = 1; i <= n; i++) {
            dp[i] = Math.max(nums[i - 1], dp[i - 1] + nums[i - 1]);
            ret = Math.max(ret, dp[i]);
        }
        return ret;
    }
}
